package com.xpgk.mvc.outPersonnel;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.intoPersonnel.IntoPersonnel;
import com.xpgk.mvc.intoPersonnel.IntoPersonnelServices;
import com.xpgk.mvc.user.User;

public class OutPersonnelController extends BaseController{

	public void index(){
		
		//获取当前机构id
    	String  organids=getCUserOrganIds();
    	String  userids=getCUserIds();
    	String cusIds=getPara("personnelIds");
		if(cusIds != null)
		{
			User user = User.dao.findById(cusIds);
			
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("column", IntoPersonnel.column_userIds);
			String sql = getSqlByBeetl(IntoPersonnel.sqlId_column, param);
			IntoPersonnel personnel = IntoPersonnel.dao.findFirst(sql, cusIds);
			setAttr("user", user);
			setAttr("intoPersonnel", personnel);
		}
    	setAttr("organids", organids);
		setAttr("userids", userids);
		render("OutPersonnel.html");
		//render("OutPersonnel.html");
	}
	public void toUserInfo(){
		//获取当前机构id
    	String  organids=getCUserOrganIds();
    	String  userids=getCUserIds();
    	
    	setAttr("organids", organids);
		setAttr("userids", userids);
		render("OutPersonnel.html");
	}
	private OutPersonnelServices outPersonnelServices = new OutPersonnelServices();
	/**
	 * 保存基本信息
	 * */
	@Before(Tx.class)
	public  void  saveOutPer()
	{	
		String personnelIds = getPara("outPersonnel.userIds");
		
		//获取当前登录机构id
		String  cudid=getCUserOrganIds();
		OutPersonnel outPersonnel = getModel(OutPersonnel.class,"outPersonnel");
		RenderBean result=outPersonnelServices.saveOutPer(outPersonnel,personnelIds, cudid);
		renderJson(result.getMap());
	}
	
}
